<template>
	<view class="content">
		<view class="view-center">
			<text>{{ title }}</text>
		</view>

		<view class="view-center">
			<view class="title">当前手机号码:{{ uMsg.uPhone }}</view>
			<view class="title">当前OM：{{ uMsg.currnetOm }} OM</view>
			<view class="title">可提现的金额：{{ mCount }}元</view>
			<input class="uni-input" type="number" placeholder="这是一个数字输入框" @input="onKeyInput" />
			<view style="height: 100upx;"></view>
			<input class="uni-input" placeholder="请输入支付密码" @input="onKeyPassInput" />

			<button v-if="mCount > 0" class="mini-btn" type="primary" size="mini" @click="getMoney()">提现</button>
			<button v-if="mCount > 0" class="mini-btn" type="primary" size="mini" @click="forgetPassword()">忘记密码</button>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
	computed: mapGetters({
		uMsg: 'userSotre/getUmsg'
	}),

	data() {
		return {
			title: '',
			mCount: 0,
			isNoEn: false,
			passCode: 0
		};
	},

	methods: {
		onKeyInput: function(event) {
			let inputCount = Number(event.target.value || 0);
			this.isNoEn = inputCount > this.uMsg.currnetOm;
			if (this.isNoEn) {
				this.omNtEn();
				return;
			}
			this.mCount = inputCount / this.uMsg.baseTurn;
		},

		onKeyPassInput: function(event) {
			this.passCode = Number(event.target.value || 0);
		},

		getMoney: function() {
			if (!this.isNoEn) {
				let isLastCount = Number(this.uMsg.currnetOm - this.mCount * this.uMsg.baseTurn);
				if (isLastCount < 0) {
					this.omNtEn();
					return;
				}
				this.uMsg.currnetOm = isLastCount;
			}
		},

		forgetPassword: function() {
			this.commonOm.navigateTo({
				url: './reset-password'
			});
		},

		omNtEn: function() {
			this.commonOm.showToast('OM不足');
		}
	}
};
</script>

<style>
.view-center {
	margin: 0 auto;
}
</style>
